package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.PmsCategoryEntity;
import com.atguigu.gulimall.product.service.PmsCategoryService;
import com.atguigu.gulimall.product.vo.Catelog2Vo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Resource
    private PmsCategoryService pmsCategoryService;

    @GetMapping({"/","/index.html"})
    public String getIndex(Model model){
        //查询一级分类
        QueryWrapper<PmsCategoryEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("parent_cid","0");
        List<PmsCategoryEntity> list = pmsCategoryService.list(queryWrapper);
        model.addAttribute("categorys",list);
        return "index";
    }

    @ResponseBody
    @RequestMapping("index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatlogJson() {

        Map<String, List<Catelog2Vo>> map = pmsCategoryService.getRedissonCatelogJson();
        return map;
    }
}
